﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Net;
using Cdn.Blogger.Models;

namespace Cdn.Blogger.Controllers
{
    public class ProxyController : Controller
    {
        
        public ActionResult Index()
        {
            RestCall call = new RestCall();
            return View(call);
        }
        public ActionResult Scripts(string version)
        {
            RestCall call = new RestCall();
            Response.AddHeader("Content-type", "text/javascript");
            if (string.IsNullOrEmpty(version) == false && version.ToLower().Contains("api") == true)
            {
                //Need file based template
                return View(call);
            }
            else
            {
             return Content("//This file is not available with us.");
            }
        }
        public ActionResult Get(string version)
        {
            RestCall call = new RestCall();
            return View(call);
        }
        public ActionResult Post(string version)
        {
            RestCall call = new RestCall();
            double d = 0;
            double.TryParse(version, out d);
            return View(call);
        }
        public ActionResult Put(string version)
        {
            RestCall call = new RestCall();
            return View(call);
        }
        public ActionResult Delete(string version)
        {
            RestCall call = new RestCall();
            return View(call);
        }

        public ActionResult Text(string version, string url)
        {
            try
            {
                WebClient client = new WebClient();
                var html =  client.DownloadString(url);
                return Content(html);
            }
            catch (Exception webEx)
            {
                return Content("Failure in getting web content");
            }
        }
    }
}
